package com.quick.framework.security.handle;

import com.quick.common.core.domain.LoginUser;
import com.quick.common.redis.RedisCache;
import com.quick.framework.service.PasswordService;
import com.quick.framework.service.UserLoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;

import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;


/**
 * 密码登录
 *
 * @Author: Administrator
 * @Date: 2023/7/27
 */
@Service
public class PasswordLoginHandlerImpl implements UserDetailsService {
    @Autowired
    private UserLoginService userLoginService;
    @Autowired
    private PasswordService passwordService;


    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        LoginUser loginUser = userLoginService.selectSysUserByUserName(username);
        passwordService.validate(loginUser.getPassword());
        userLoginService.setUserAgent(loginUser);
        userLoginService.setPermission(loginUser);
        return loginUser;
    }
}
